package fm.jiecao.jiecaovideoplayer;

import android.app.Application;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

/**
 * Created by Nathen
 * On 2015/12/01 11:29
 */
public class DemoApplication extends Application {

  @Override
  public void onCreate() {
    super.onCreate();
    initUniversalImageLoader();

  }

  private void initUniversalImageLoader() {
    ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(getApplicationContext());
    config.threadPriority(Thread.NORM_PRIORITY - 2);
    config.denyCacheImageMultipleSizesInMemory();
    config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
    config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
    config.tasksProcessingOrder(QueueProcessingType.LIFO);
    config.writeDebugLogs(); // Remove for releaseAllVideos app
    config.defaultDisplayImageOptions(getDefaultDisplayImageOption());
    // Initialize ImageLoader with configuration.
    ImageLoader.getInstance().init(config.build());
  }

  public static DisplayImageOptions getDefaultDisplayImageOption() {
    DisplayImageOptions options = new DisplayImageOptions.Builder()
      .showImageOnLoading(new ColorDrawable(Color.parseColor("#f0f0f0")))
      .resetViewBeforeLoading(true)
      .cacheInMemory(true)
      .cacheOnDisk(true)
      .considerExifParams(true)
      .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
      .bitmapConfig(Bitmap.Config.RGB_565)
      .displayer(new FadeInBitmapDisplayer(500)) // 设置图片渐显的时间
//                .delayBeforeLoading(300)  // 下载前的延迟时间
      .build();
    return options;
  }

}
